<?php $this->headLink()
->appendStylesheet($this->Css('button.css'))
->appendStylesheet($this->js('plugins/css/jquery.autocomplete.css'));

$this->headScript()
->appendFile($this->js('plugins/jquery.selectboxes.js'))
->appendFile($this->js('plugins/jquery.autocomplete.min.js'))
?>
<style type="text/css">
#classList { margin:10px;padding:2px;overflow:auto; height:300px;width:500px;background:#dde}

#list_teacher span  a {margin:5px;padding:5px;}
#list_teacher a {text-decoration:none;}
.class_detail {background:#ffe;margin:5px;padding:5px;}
.class_detail li {margin:3px;cursor:pointer;}
.selected {background:#ff0}
.teacher_selected {background:#ff0}
.class-teacher {margin:2px;}
</style>
<script type="text/javascript">

var teachers_arr = <?php echo $this->teachers?>;
var teachers_sn = <?php echo $this->teachers_sn?>;
$(document).ready(function(){
	$("#year_semester").change(function(){
		$("#setform").submit();
	});
	$("#teacher_select").addOption(teachers_sn,false);
	$("#teacher_select").change(function(){
		$(".select_box").empty();
	});

	$(".class_detail a").click(function(){
		$(".selected").removeClass('selected');
		$(".select_box").empty();
		$(this).addClass('selected');
		$(this).siblings('div').children('.select_box').html("<select></select>");
		var id = $("#teacher_select option:selected").text();
		var aa = teachers_arr[id];
		$(".select_box select").addOption('','<?php echo $this->translate('select')?> '+id);
		$.each(aa,function(i,data){
		$(".select_box select").addOption(data.username,data.name);
		});
		$(".select_box select").selectOptions('');

	});

	$(".auto-search").autocomplete("<?php echo $this->route('search') ?>", {
        width: 260,
        selectFirst: false,
        extraParams: {
		  year_semester : $("#year_semester").val()
        }
    });
	$(".auto-search").result(function(event, data, formatted) {
        if (data) {
            var id = $(this).attr('id').substring(2);
            $("#t-"+id).val(data[1]);
        }
    });


});
</script>
<form id="setform" action="" method="post">
<select name="year_semester" id="year_semester">
<?php echo  $this->YearSemesterOptions($this->year_semester) ?>
</select>
<input type="submit" name="act" value="<?php echo $this->translate('save')?>"/>

<table style="margin:10px auto; width:100%;border:1px solid #ccc">
<?php $i = 0;?>
<?php foreach($this->class_name as  $id=>$val):?>
<?php if ($i % 3 == 0):?><tr><?php endif?>
<td style="vertical-align: top; padding:5px">
<h3><?php echo $id?></h3>

<?php foreach($val as $class_sn=>$class_name):?>
<p class="class-teacher">
<span style="background: #ffa;margin:3px;padding:2px;border:thin solid #ccc"><?php echo $class_name?></span>
<?php if(isset($this->toturs[$class_sn])):?>
<?php foreach($this->toturs[$class_sn] as $tt):?>
<input class="auto-search"  type="text"   id="c-<?php echo $class_sn?>"   value="<?php echo $tt['name']?>"  size="8"/>
<input type="hidden"  id="t-<?php echo $class_sn?>"  name="class_id[<?php echo $class_sn?>]"  value="<?php echo $tt['teacher_id']?>" />
<?php endforeach;?>
<?php else:?>
<input  id="c-<?php echo $class_sn?>" class="auto-search" type="text"  value=""  size="8"/>
<input type="hidden"  id="t-<?php echo $class_sn?>"  name="class_id[<?php echo $class_sn?>]"  />
<?php endif?>

</p>
<?php endforeach;?>

</td>
<?php if ($i++ % 3 == 2):?></tr><?php endif?>
<?php endforeach;?>
</table>
</form>
<div style="clear:both"></div>